import { MaxHeap } from '../dataStructure/Heap'

export const heapSort = (arr) => {
    const maxHeap = new MaxHeap()

    for (let el of arr) {
        maxHeap.add(el)
    }

    for (let i = arr.length - 1; i >= 0; i--) {
        arr[i] = maxHeap.extractMax()
    }

    return arr
}

export const heapSort2 = (arr) => {
    const maxHeap = new MaxHeap(arr)

    for (let i = arr.length - 1; i >= 0; i--) {
        arr[i] = maxHeap.extractMax()
    }

    return arr
}